package com.ly.mpayment.persist.service.yidong;

import java.io.Serializable;

import org.springframework.stereotype.Service;

import com.ly.mpayment.persist.entity.yidong.SmsCode;
import com.ly.mpayment.persist.service.AbstractService;
@Service
public class SmsCodeServiceImpl extends AbstractService<SmsCode, Serializable> implements ISmsCodeService {

	@Override
	public boolean saveCode(SmsCode code) {
		if(code != null){
			this.saveOrUpdate(code);
			return true;
		}
		return false;
	}

	@Override
	public boolean updateCode(SmsCode code) {
		if(code != null){
			this.updateEntity(code);
			return true;
		}
		return false;
	}

	@Override
	public SmsCode findByPhone(String phone) {
		return this.findOneObject("select s from SmsCode s where s.phone = ?", phone);
	}

	@Override
	public SmsCode findById(String id) {
		return this.findUnique("select s from SmsCode s where s.id = ?", id);
	}

	@Override
	public SmsCode findByPhone(String phone, String code) {
		return this.findOneObject("select s from SmsCode s where s.phone = ? and s.smsCode is null", phone);
	}

}
